package com.self.springframework.beans.factory.support;

import com.self.springframework.beans.factory.config.BeanDefinition;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.NoOp;

import java.lang.reflect.Constructor;
import java.lang.reflect.TypeVariable;

public class CglibSubclassInstantiationStrategy extends SimpleInstantiationStrategy{

    @Override
    public Object instantiate(BeanDefinition beanDefinition, String beanName, Constructor<?> constructor, Object[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(beanDefinition.getBeanClass());
        enhancer.setCallback(new NoOp() {});
        if (args==null) return enhancer.create();
        return enhancer.create(constructor.getParameterTypes(),args);
    }
}
